package com.yangjiangtao;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

@WebServlet("/LoginServlet")
public class LoginServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws IOException {
        String username = request.getParameter("username");
        String password = request.getParameter("password");


        // 假设这里的逻辑是简单的用户名和密码匹配，实际应用中应该使用数据库或其他存储方式进行验证
        if ("admin".equals(username) && "admin".equals(password)) {
            // 登录成功
            User user = new User(username,password);
            HttpSession session = request.getSession();
            session.setAttribute("user", user);
            response.sendRedirect("loginSuccess.jsp");
        } else {
            // 登录失败
            response.sendRedirect("index.jsp");
        }
    }
}